<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <title>创建模版</title>
    <link rel="stylesheet" href="/style/weui.css"/>
    <link rel="stylesheet" href="/style/swiper.min.css"/>
    <link rel="stylesheet" href="/style/example.css"/>
    <link rel="stylesheet" href="/style/jquery-weui.css">
    <link rel="stylesheet" href="/style/sweetalert.css"/>
</head>
<body ontouchstart>
<div class="page">
    <div class="page__bd" style="height: 100%;">
        <div class="weui-tab">
            <div class="weui-navbar">
                <a class="weui-navbar__item weui-bar__item--on" href="#productBox">
                    产品&nbsp;<span style="color: red" id="pro_cnt">
                        <?= count($tempDtl['pro']) ?>
                    </span>
                </a>
                <a class="weui-navbar__item" href="#materielBox">
                    物料&nbsp;<span style="color: red" id="mat_cnt">
                        <?= count($tempDtl['mat']) ?>
                    </span>
                </a>
            </div>
            <div class="weui-tab__bd">
                <div id="productBox" class="weui-tab__bd-item weui-tab__bd-item--active">
                    <div class="weui-panel__bd">
                        <?php foreach ($list['pro'] as $val) { ?>
                            <div class="weui-media-box weui-media-box_appmsg weui-cells_checkbox">
                                <div class="weui-media-box__bd">
                                    <h4 class="weui-media-box__title"><?=$val['name']?></h4>
                                    <p class="weui-media-box__desc"><?=$val['typeName']?></p>
                                </div>
                                <div class="weui-media-box__hd" style="height: auto; line-height: 0">
                                    <label class="weui-cell weui-check__label" for="pro-<?=$val['id']?>">
                                        <input type="checkbox" class="weui-check" name="check-pro" data-type="2" data-value="<?=$val['id']?>" id="pro-<?=$val['id']?>"
                                                <?= isset($tempDtl['pro'][$val['id']]) ? 'checked' : '' ?>>
                                        <i class="weui-icon-checked"></i>
                                    </label>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </div>

                <div id="materielBox" class="weui-tab__bd-item">
                    <div class="weui-panel__bd">
                        <?php foreach ($list['mat'] as $val) { ?>
                            <div class="weui-media-box weui-media-box_appmsg weui-cells_checkbox">
                                <div class="weui-media-box__bd">
                                    <h4 class="weui-media-box__title"><?=$val['name']?>&nbsp;&nbsp;<span style="color: #999999"><?=$val['typeName']?></span></h4>
                                    <p class="weui-media-box__desc"><?=$val['specDesc']?></p>
                                    <p class="weui-media-box__desc"><?=$val['packDesc']?></p>
                                    <?php if( isset($val['ext1']) &&  $val['ext1'] == 1) { ?>
                                        <p class="weui-media-box__desc">
                                            <span class="text-red">盘点单位:<?=$val['useDesc']?></span>
                                        </p>
                                    <?php } ?>

                                </div>
                                <div class="weui-media-box__hd" style="height: auto; line-height: 0">
                                    <label class="weui-cell weui-check__label" for="mat-<?=$val['id']?>">
                                        <input type="checkbox" class="weui-check" name="check-mat" data-type="1" data-value="<?=$val['id']?>" id="mat-<?=$val['id']?>"
                                            <?= isset($tempDtl['mat'][$val['id']]) ? 'checked' : '' ?>>
                                        <i class="weui-icon-checked"></i>
                                    </label>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </div>
            </div>

            <div class="weui-form-preview__ft weui-footer_fixed-bottom" style="background-color: #fff; bottom: 0">
                <?php if(!empty($editFlg)) { ?>
                    <a class="weui-form-preview__btn" href="/inventory/template?pageFlg=1">返回</a>
                    <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:saveTemp()">保存</a>
                <?php } else{ ?>
                    <a class="weui-form-preview__btn" href="/inventory/template-list">返回</a>
                <?php } ?>
            </div>
        </div>
    </div>
</div>
<script src="/js/zepto.min.js"></script>
<script src="/js/sweetalert.min.js"></script>
<script src="/js/swiper.min.js"></script>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="https://res.wx.qq.com/open/libs/weuijs/1.0.0/weui.min.js"></script>
<script src="/js/swiper.min.js"></script>
<script src="/js/jquery-weui.js"></script>
<script>

    $(function () {
        $('input[name=check-pro]').on('click', function () {
            var cnt = $('#pro_cnt').html();
            cnt = cnt ? parseInt(cnt) : 0;
            if ($(this).is(':checked')) {
                cnt++;
            } else {
                cnt--;
            }
            $('#pro_cnt').html(cnt);
        });
        $('input[name=check-mat]').on('click', function () {
            var cnt = $('#mat_cnt').html();
            cnt = cnt ? parseInt(cnt) : 0;
            if ($(this).is(':checked')) {
                cnt++;
            } else {
                cnt--;
            }
            $('#mat_cnt').html(cnt);
        });
    })

    function saveTemp() {
        var selectData = [];
        $.each($('input:checked'), function () {
            selectData.push({'id': $(this).attr('data-value'), 'type': $(this).attr('data-type')})
        });

        if (!selectData.length) {
            swal('请选择模版数据');
            return;
        }
        $.post(
            '/inventory/save-template', {'selectData': selectData},
            function (o) {
                if (o.code == 200) {
                    swal('保存成功');
                    setTimeout(function () {
                        location.href = '/inventory/template-list';
                    }, 1500);
                } else {
                    swal('保存失败');
                }
            },
            'json'
        );
    }

</script>
</body>
</html>
